package com.cn.xiaonuo.common.utils;

import com.anji.captcha.util.StringUtils;

import java.math.BigDecimal;

public class GetJavaTypeConvert {

    public static String getString(Object obj){
        if(obj instanceof String){
            return (String)obj;
        }else if(obj instanceof Integer){
            return String.valueOf((Integer)obj);
        }else if(obj instanceof Long){
            return String.valueOf((Long)obj);
        }else if(obj instanceof Double){
            return String.valueOf((Double)obj);
        }else if(obj instanceof Short){
            return String.valueOf((Short)obj);
        }
        return null;
    }

    public static Integer getInteger(Object obj){
        if(obj instanceof Integer){
            return (Integer)obj;
        }else if(obj instanceof String){
            if(StringUtils.isNotBlank((String)obj)){
                return Integer.parseInt((String)obj);
            }
        }
        return null;
    }

    public static Double getDouble(Object obj){
        if(obj instanceof Double){
            return (Double)obj;
        }else if(obj instanceof String){
            if(StringUtils.isNotBlank((String)obj)){
                return Double.parseDouble((String)obj);
            }
        }
        return null;
    }

    public static BigDecimal getBigDecimal(Object obj){
        if(obj instanceof String){
            BigDecimal bigDecimal = new BigDecimal((String) obj);
            return bigDecimal;
        }else if(obj instanceof Integer){
            BigDecimal bigDecimal = new BigDecimal((Integer) obj);
            return bigDecimal;
        }else if(obj instanceof Long){
            BigDecimal bigDecimal = new BigDecimal((Long) obj);
            return bigDecimal;
        }else if(obj instanceof Double){
            BigDecimal bigDecimal = new BigDecimal((Double) obj);
            return bigDecimal;
        }else if(obj instanceof Short){
            BigDecimal bigDecimal = new BigDecimal((Short) obj);
            return bigDecimal;
        }else if(obj instanceof BigDecimal){
            return (BigDecimal)obj;
        }
        return null;
    }
    public static Long getLong(Object obj){
        if(obj instanceof Long){
            return (Long)obj;
        }else if(obj instanceof String){
            if(org.apache.commons.lang3.StringUtils.isNotBlank((String)obj)){
                return Long.parseLong((String)obj);
            }
        }
        return null;
    }

}
